package cn.ronghuanet.base.controller;

import cn.ronghuanet.base.service.IFastdfsService;
import cn.ronghuanet.base.util.AjaxResult;
import cn.ronghuanet.base.util.FastdfsUtil;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/fastDfs")
public class FastdfsController {

    @Autowired
    private IFastdfsService fastdfsService;

    @PostMapping("/upload")
    public AjaxResult upload(MultipartFile file) throws Exception{
        String path = fastdfsService.upload(file);
        return AjaxResult.success(path);
    }

    /**
     * 后端controller接收前端传递的参数的方式有哪些??
     *    url传参,通过Pathvi...来获取
     *    对象接收
     *    参数名接收
     *    request.getParamter()
     * @param path
     * @return
     */
    @DeleteMapping
    public AjaxResult delete(String path){
        fastdfsService.delete(path);
        return AjaxResult.success();
    }
}
